package com.qd.common.panda.domain.entity.plate;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.cdqidi.util.page.BaseQuery;
import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.DeleteGroup;
import com.cdqidi.valid.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.Optional;


/**
 * 用户和车牌关系
 *
 * @author sjk
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
@ToString
public class UserPlateRelationDTO extends BaseQuery {

    @ExcelIgnore
    @JsonIgnore
    private static final String EXCEL_TITLE = "用户和车牌关系";
    /**
     * 主键
     */
    @ExcelProperty(value = {EXCEL_TITLE, "关系ID"})
    @NotBlank(message = "关系ID不能为空", groups = {DeleteGroup.class, UpdateGroup.class})
    @Size(max = 50, message = "关系ID长度不能超过{max}位", groups = {DeleteGroup.class, UpdateGroup.class})
    @JsonProperty("rid")
    private String rId;
    /**
     * 车牌
     */
    @ExcelProperty(value = {EXCEL_TITLE, "车牌"})
    @NotBlank(message = "车牌不能为空", groups = DefaultGroup.class)
    @Size(max = 20, message = "车牌长度不能超过{max}位", groups = DefaultGroup.class)
    private String plateNumber;
    /**
     * 用户唯一标识
     */
    @ExcelProperty(value = {EXCEL_TITLE, "用户唯一标识"})
    @NotBlank(message = "用户唯一标识不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "用户唯一标识长度不能超过{max}位", groups = DefaultGroup.class)
    private String userId;
    /**
     * 充电是否自动确认
     */
    @ExcelIgnore
    @Size(max = 50, message = "充电是否自动确认长度不能超过{max}位", groups = DefaultGroup.class)
    private String autoConfirmCharge;
    /**
     * 充电是否自动确认显示
     */
    @ExcelProperty(value = {EXCEL_TITLE, "充电是否自动确认"})
    private String autoConfirmChargeDisplay;
    /**
     * 车牌信息
     */
    @ExcelIgnore
    private PlateDTO plate;
    /**
     * 添加时间
     */
    private LocalDateTime addTime;
    /**
     * 手机号
     */
    private String mobile;

    @Override
    public void freeData() {
        this.rId = null;
        this.plateNumber = null;
        this.userId = null;
        this.autoConfirmCharge = null;
        this.autoConfirmChargeDisplay = null;
        this.addTime = null;
        this.mobile = null;
        Optional.ofNullable(plate).ifPresent(PlateDTO::freeData);
        super.freeData();
    }
}
